package com.ruoyi.client.controller;

import com.ruoyi.client.pojo.vo.IndexCarouselVo;
import com.ruoyi.client.pojo.vo.IndexDataVo;
import com.ruoyi.client.pojo.vo.IndexNovelVo;
import com.ruoyi.client.pojo.vo.NovelVo;
import com.ruoyi.client.service.IIndexService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.novel.service.IIndexCarouselService;
import org.springframework.data.redis.core.convert.IndexedData;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Anonymous//允许匿名访问
@CrossOrigin
@RestController
public class IndexController {
    @Resource
    private IIndexService indexService;
    @GetMapping("/index")
    public AjaxResult index(){
        //轮播数据
        List <IndexCarouselVo> carouselItems=indexService.listCarouselItems();
        List <NovelVo> novelItems=indexService.listNovelItems();
        List <NovelVo> rankingItems=indexService.listRankingItems();

        IndexDataVo indexDataVo=new IndexDataVo();
        indexDataVo.setCarouselItems(carouselItems);
        indexDataVo.setNovelItems(novelItems);
        indexDataVo.setRankingItems(rankingItems);

        return AjaxResult.success(indexDataVo);
    }
    
    // 添加获取点赞榜数据的接口
    @GetMapping("/likeRanking")
    public AjaxResult likeRanking() {
        List<NovelVo> likeRankingItems = indexService.listLikeRankingItems();
        
        IndexDataVo indexDataVo = new IndexDataVo();
        indexDataVo.setRankingItems(likeRankingItems);
        
        return AjaxResult.success(indexDataVo);
    }
}